import {message} from 'antd';
import {formatMessage} from './intl';

export const newOrUpdateOrderValidator = (data, details) => {
    const requiredFields = [];
    if(!data || !data.brandId)
        requiredFields.push(
            formatMessage({
                id: 'validator.brandId',
                defaultMessage: '品牌'
            })
        );
    if(!data || !data.code)
        requiredFields.push(
            formatMessage({
                id: 'validator.code',
                defaultMessage: '货代编码'
            })
        );
    if(!data || !data.name)
        requiredFields.push(
            formatMessage({
                id: 'validator.name',
                defaultMessage: '货代名称'
            })
        );
    if(!data || !data.shortName)
        requiredFields.push(
            formatMessage({
                id: 'validator.shortName',
                defaultMessage: '货代简称'
            })
        );
    if(requiredFields.length > 0) {
        message.warning(`${requiredFields.join('，')}${formatMessage({
            id: 'validator.requied',
            defaultMessage: '必填'
        })}`);
        return false;
    }
    if(details.find(d => !d.contact)) {
        message.warning(`${requiredFields.join('，')}${formatMessage({
            id: 'validator.contact',
            defaultMessage: '货代联系人必填!'
        })}`);
        return false;
    }
    if(details.find(d => !d.contactNumber)) {
        message.warning(`${requiredFields.join('，')}${formatMessage({
            id: 'validator.contactNumber',
            defaultMessage: '货代电话必填!'
        })}`);
        return false;
    }
    return true;
};
